using System;
using System.Collections.Generic;
using System.Text;

public class crossquestion
{
    public string question;
    public string answer;
    public int answered;
    public int start;
    public int length;
}
public class crossword
{
    public int numberQuestion=0;
    public crossquestion[] questions;
    public void init()
    {
        questions = new crossquestion[numberQuestion];
    }

}
public class stoneGlobal
    {
        public struct clients{
            public int port;
            public string IP;
            public string name;
            public int number;
            public int mark;
        }
        public struct answers
        {
            public int computer;
            public string data;
            public int timecount;
        }
        public struct stages
        {
            public string code;
            public int mark;
            public int timeUp;
            public int numberQuestion;
        }
        static public int waitfor=10000;
        public static crossword five=null;
        public static int[] questionlist;
        public static string IP="";
        public static int port=456;
        public static string serverIP="";
        public static int serverPort=456;
        public static int groupNumber = 0;
        public static string groupName="";
        public static int numberClient;
        public static int maxClient = 5;
        public static int maxAnswer = 4;
        public static int numberAnswer = 0;
        public static clients[] cls;
        public static stages[] sta;
        public static answers[] al;
        public static int numberStage=0;
        public static int currentStage=0;
        public static int answerType=0;
        public static int allowEA = 1;
        public static int answerComputer=0;
        public static bool acceptAnser = false;
        public static int[] stopCrossword;
        public static int numberStopCrossword = 0;
    public static void stopGroup(int group)
    {
        stopCrossword[numberStopCrossword] = group;
        numberStopCrossword++;

    }
    public static bool isProhibit(int group)
    {
        bool pro = false;
        int i;
        for (i = 0; i < numberStopCrossword; i++)
        {
            if (stopCrossword[i] == group)
            {
                pro = true;
                break;
            }
        }
        return pro;
    }
    public static void markSet(int computer, int mark)
        {
            if (cls[computer].name != "")
            {
                cls[computer].mark = mark;
            }
        }
        public static void markAnswer(int computer, int mark)
        {
            if (cls[computer].name != "")
            {
                cls[computer].mark += mark;
            }
        }
        public static string getTimeUp()
        {
            string st = "";
            int i, count = 0;

            for (i = 0; i < numberStage; i++)
            {
                if (sta[i].code != "")
                {
                    if (count != 0)
                    {
                        st += ",";
                    }
                    count++;
                    st += sta[i].timeUp.ToString();
                }
            }
            return st;
        }
        public static string getQuestionCount()
        {
            string st="";
            int i,count=0;

            for (i = 0; i < numberStage; i++)
            {
                if (sta[i].code != "")
                {
                    if (count != 0)
                    {
                        st += ",";
                    }
                    count++;
                    st += sta[i].numberQuestion.ToString();
                }
            }
            return st;
        }
        public static void initClient()
        {
            cls = new clients[maxClient];
            sta = new stages[5];
            al = new answers[maxAnswer];
            stopCrossword = new int[10];
            for (int i = 0; i < 5; i++)
            {
                cls[i].number = -1;
                cls[i].mark = 0;
                sta[i].code = "";
            }
        }
        public static void clearAnswer()
        {
            stoneGlobal.numberAnswer = 0;
        }
        public static void addAnswer(int timecount, int computer, string data)
        {
            int i,vt=-1;
            for (i = 0; i < stoneGlobal.numberAnswer; i++)
            {
                if (al[i].computer == computer)
                {
                    vt = i;
                    break;
                }
            }
            if (vt != -1)
            {
                for (i = vt; i < stoneGlobal.numberAnswer - 1; i++)
                {
                    al[i] = al[i + 1];
                }
                al[stoneGlobal.numberAnswer - 1].computer = computer;
                al[stoneGlobal.numberAnswer - 1].timecount= timecount;
                al[stoneGlobal.numberAnswer - 1].data= data;
            }
            else
            {
                stoneGlobal.numberAnswer++;
                al[stoneGlobal.numberAnswer - 1].computer = computer;
                al[stoneGlobal.numberAnswer - 1].timecount = timecount;
                al[stoneGlobal.numberAnswer - 1].data = data;
            }
        }
        public static void addClient(int computer, string name, string IP, int port)
        {
            cls[computer].number = computer;
            cls[computer].IP = IP;
            cls[computer].name = name;
            cls[computer].port = port;
        }
    public static string timeFormat(int t)
    {
        int h, m;
        string v="";
        h = t / 60;
        m = t % 60;
        if (h > 0)
            v = h.ToString()+":";
        v += m.ToString("00");
        return v;
    }

    }
